package org.NooLab.nativebrowser.gui.hidden;

import java.awt.BorderLayout;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;

import javax.swing.JButton;
import javax.swing.JFrame;

import javax.swing.JPanel;
 
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.WindowConstants;

import org.NooLab.nativebrowser.app.config.ITexxAppPropertiesIntf;
import org.NooLab.nativebrowser.components.NativeBrowserCommons;
import org.NooLab.nativebrowser.components.WebBrowserAppMainIntf;

import org.NooLab.utilities.logging.PrintLog;





/**
 * 
 * 
 * @author kwa
 *
 */
public class HiddenWindow implements HiddenWindowGuiIntf {

	protected static int clics = 0;

	// ITexxWindow texxWindowApp ;
	WebBrowserAppMainIntf iTexxWindowApp;

	private JFrame frame;

	float transparencyOfVisible = 0.8f;

	JPanel parentBasePanel;
	JPanel jPanel1;
	private boolean windowIsTransparent;

	PrintLog out = new PrintLog(2, false);

	HiddenWindow windowGui;

	private JPanel contentPanel;
	private NativeBrowserCommons appCommons;

	private boolean isSimpleWindow;
	private JPanel jPanelWebMeta;
	private JTextField TextFieldDedicatedSearch;
	private JPanel PanelMetaSearchBrowser;
	private JButton jButtonSingleWindow;

	private ITexxAppPropertiesIntf appProperties;

	// ========================================================================
	public HiddenWindow(WebBrowserAppMainIntf iTexxWindow) {
		//
		frame = iTexxWindow.getMainFrame();

		iTexxWindowApp = iTexxWindow;
		windowGui = this;

		appCommons = iTexxWindowApp.getAppCommons();

		appProperties = appCommons.getAppProperties();

	}

	// ========================================================================

	@SuppressWarnings("unused")
	public void createITexxWindowGui() {
		//
		boolean decoratedWindow = true; // command line: show window handles on
										// next start

		Dimension d, basicdim;

		out.setPrefix("[NNB]");
		out.print(2, "starting (1) ...");

		int basicWidth = 350;
		int basicHeight = 650;

		d = new Dimension(basicWidth, basicHeight);
		basicdim = new Dimension(basicWidth, basicHeight);

		// get screen width
		frame.setLocation(1400, 150);

		frame.setSize(basicWidth + 20, basicHeight);

		d = new Dimension(basicWidth / 2, basicHeight / 3);
		frame.setMinimumSize(d);
		frame.setSize(basicdim);
		frame.setPreferredSize(basicdim);

		frame.setResizable(true);
		frame.setUndecorated(false); // this comes from gui

		setlookandfeel();

		frame.setExtendedState(Frame.NORMAL); // for fullscreen ->
												// Frame.MAXIMIZED_BOTH

		if (appProperties == null) {
			appProperties = this.appCommons.getAppProperties();
		}

		frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

		// this panel will contain all further components and it will be
		// invisible will be pale red
		parentBasePanel = new JPanel(); //
		parentBasePanel.setOpaque(windowIsTransparent);
		parentBasePanel.setVisible(true);

		parentBasePanel.setToolTipText("parentBasePanel = top panel");

		// FlowLayout parentBasePanelLayout = new FlowLayout();
		BorderLayout parentBasePanelBorderLayout = new BorderLayout();
		parentBasePanel.setLayout(parentBasePanelBorderLayout);

		d = new Dimension(basicWidth / 2, basicHeight);
		parentBasePanel.setMinimumSize(d);

		int maxWidth = (int) 400;
		parentBasePanel.setMaximumSize(new java.awt.Dimension(maxWidth, 300));
		parentBasePanel.setPreferredSize(basicdim);
		parentBasePanel.setSize(basicdim);

		parentBasePanel.setFocusable(true);
		parentBasePanel.setEnabled(true);

		frame.add(parentBasePanel);

		{ // A panel that is holding the main tabbedPane and a statusbar Panel
			// (yet to do...)
			contentPanel = new JPanel();
			BorderLayout contentPanelLayout = new BorderLayout();
			contentPanel.setLayout(contentPanelLayout);

			contentPanel.setToolTipText("contentPanel");
			contentPanel.setName("contentPanel");
			contentPanel.setMinimumSize(new java.awt.Dimension(50, 350));

			int w = parentBasePanel.getWidth() - 4;
			contentPanel.setPreferredSize(new java.awt.Dimension(w, basicHeight - 20));

			contentPanel.setOpaque(true); // false = invisible showBasePanel );
			contentPanel.setVisible(true);

			parentBasePanel.add(contentPanel, BorderLayout.CENTER);

			{
				PanelMetaSearchBrowser = new JPanel();
				BorderLayout PanelMetaSearchBrowserLayout = new BorderLayout();
				PanelMetaSearchBrowser.setLayout(PanelMetaSearchBrowserLayout);
				parentBasePanel.add(PanelMetaSearchBrowser, BorderLayout.CENTER);
				PanelMetaSearchBrowser.setName("PanelMetaSearchBrowser");

				PanelMetaSearchBrowser.setBackground(new Color(226, 208, 200));
			}

		} // contentPanel

	}

	public JButton getjButtonSingleWindow() {
		return jButtonSingleWindow;
	}


	private void setlookandfeel() {

		try {
			// Set cross-platform Java L&F (also called "Metal")

			// UIManager.setLookAndFeel(UIManager.get);
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");

			//

		} catch (UnsupportedLookAndFeelException e) {
			// handle exception
		} catch (ClassNotFoundException e) {
			// handle exception
		} catch (InstantiationException e) {
			// handle exception
		} catch (IllegalAccessException e) {
			// handle exception
		}

	}

	@Override
	public void setAppCommons(NativeBrowserCommons appcommons) {
		//
		appCommons = appcommons;
	}

	public NativeBrowserCommons getAppCommons() {
		return appCommons;
	}

	@Override
	public WebBrowserAppMainIntf getTexxWindowApp() {
		return iTexxWindowApp;
	}

	@Override
	public PrintLog getOut() {
		//
		return out;
	}

	@Override
	public JPanel getTopPanel() {
		return parentBasePanel;
	}

	public boolean isSimpleWindow() {
		return isSimpleWindow;
	}

	public void setSimpleWindow(boolean isSimpleWindow) {
		this.isSimpleWindow = isSimpleWindow;
	}

	@Override
	public JPanel getPanelMetaSearchBrowser() {
		return PanelMetaSearchBrowser;
	}

	public JTextField getTextFieldDedicatedSearch() {
		return TextFieldDedicatedSearch;
	}

	@Override
	public JPanel getjPanelWebMeta() {
		return jPanelWebMeta;
	}
}
